package com.hex.ds.hdtp.core.app.script.analyze.dto.response;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.app.script.analyze.dto.response
 * @ClassName ScriptAnalyzeListResponseDto
 * @Description 脚本分析清单-response对象
 * @Author gj.xu
 * @Date 2023/12/7 16:59
 * @Version v2.0
 **/
@Data
@Accessors(chain = true)
public class ScriptAnalyzeListResponseDto {

    private String pkId;

    private String analyzeTaskPkId;

    private String sourceConnPkId;

    private String targetConnPkId;

    private String sourceFileName;

    private String sourceFilePath;

    private String sourceFileSize;

    private String status;

    private String analyzeStartTs;

    private String analyzeEndTs;

    private String analyzeLog;

    private String crtUser;

    private String crtUserName;

    private String crtTs;

    private String sourceTableNames;

    private String targetTableNames;

    private List<String> sourceTableNameList;

    private List<String> targetTableNameList;

    public List<String> getSourceTableNameList() {
        if (StrUtil.isNotBlank(sourceTableNames)) {
            return Arrays.asList(StrUtil.split(sourceTableNames, ","));
        }
        return new ArrayList<>();
    }

    public List<String> getTargetTableNameList() {
        if (StrUtil.isNotBlank(targetTableNames)) {
            return Arrays.asList(StrUtil.split(targetTableNames, ","));
        }
        return new ArrayList<>();
    }

    public String getSourceFileAbsolutePath() {
        return FilenameUtils.separatorsToUnix(sourceFilePath + File.separator + sourceFileName);
    }
}
